//
//  SSStatusModel.swift
//  weibo
//
//  Created by 邵帅 on 16/6/27.
//  Copyright © 2016年 groupNineObject. All rights reserved.
//

import UIKit

class SSStatusModel: NSObject {
    
    ///  created_at	string	微博创建时间
    var created_at: String?
    
    ///id	int64	微博ID
    var id: Int = 0
    ///text	string	微博信息内容
    var text: String?
    
    ///source	string	微博来源
    var source: String?
    
    /// reposts_count	int	转发数
    var reposts_count: Int = 0
    ///comments_count	int	评论数
    var comments_count: Int = 0
    /// attitudes_count	int	表态数
    var attitudes_count: Int = 0
    
    // 用户模型
    var user: SSStatusUserModel?
    
    // 转发微博模型
    var retweet_status: SSStatusModel?
    
    // 配图数组
    var picture_urls: [SSPhotoViewModel]?
    
    init(dict: [String: AnyObject]) {
        
        super.init()

        // 这个方法才是调用 KVC动态赋值的语句
        setValuesForKeysWithDictionary(dict)
        
        
        // 我们需要手动的进行 字典里字典进行转模型
        if let userDict = dict["user"] as? [String: AnyObject] {
            
            user = SSStatusUserModel(dict: userDict)
            
        }
        
        if let retweetDict = dict["retweeted_status"] as?[String: AnyObject] {
            
            retweet_status = SSStatusModel(dict: retweetDict)
        }
        
        if let picArray = dict["pic_urls"] as?[[String: AnyObject]] {
            
            picture_urls = [SSPhotoViewModel]()
            
            for dicts in picArray {
                
                let model = SSPhotoModel(dict: dicts)
                
                let viewModel = SSPhotoViewModel(model: model)
                
                picture_urls?.append(viewModel)
            }
            
        }
        
        
    }
    
    // 为了防止崩溃
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {
        
    }
    
    
    

}
